import { Game } from './Protobuf/loginPb';
import { ProtobufUtil } from './protobufUtil';
const { ccclass, property } = cc._decorator;


@ccclass
export class ProtobufTest extends cc.Component {
    onLoad() {
    }

    start() {
        let message: Game.login_auth_s2c = Game.login_auth_s2c.create();
        message.servId = 666;
        let buffer = ProtobufUtil.pbEncode(message);
        console.log("encode: ", buffer);
        // let decoded = PlayerInfo.decode(buffer);
        let decoded: any = ProtobufUtil.pbDecode(1, 1, buffer);
        console.log("decode: ", decoded);
        this.outputPlayer(decoded as Game.login_auth_s2c);
    }

    private outputPlayer(message: Game.login_auth_s2c): void {
        console.log(`data: ${message}, serv_id: ${message.servId.toString()}`);
    }

    update(deltaTime: number) {
        
    }
}